package realestate.entity;

import realestate.manager.owner.Owner;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 12.04.11
 * Time: 18:08
 * To change this template use File | Settings | File Templates.
 */
@MappedSuperclass
public class ObjectOnMapShort implements Serializable {

	public static final String FIELD_ID = "id";
	public static final String FIELD_LONGTITUDE = "longtitude";
	public static final String FIELD_LATTITUDE = "lattitude";
	public static final String FIELD_OWNER = "owner";


	public ObjectOnMapShort() {
	}

	public ObjectOnMapShort(Long id, Double longtitude, Double lattitude) {
		this.id = id;
		this.longtitude = longtitude;
		this.lattitude = lattitude;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	@Column(name = FIELD_ID)
	private Long id;

	@Column(name = FIELD_LONGTITUDE)
	private Double longtitude;

	@Column(name = FIELD_LATTITUDE)
	private Double lattitude;

	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	private Owner owner;

	@Transient
	protected byte type;


	public Long getId() {
		return id;
	}

	public Double getLongtitude() {
		return longtitude;
	}

	public void setLongtitude(Double longtitude) {
		this.longtitude = longtitude;
	}

	public Double getLattitude() {
		return lattitude;
	}

	public void setLattitude(Double lattitude) {
		this.lattitude = lattitude;
	}

	public void setOwner(Owner owner) {
		this.owner = owner;
	}

	public Owner getOwner() {
		return owner;
	}

	public byte getType() {
		return type;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof ObjectOnMapShort)) return false;

		ObjectOnMapShort that = (ObjectOnMapShort) o;

		if (type != that.type) return false;
		if (!id.equals(that.id)) return false;
		if (!lattitude.equals(that.lattitude)) return false;
		if (!longtitude.equals(that.longtitude)) return false;
		if (!owner.equals(that.owner)) return false;

		return true;
	}

	@Override
	public int hashCode() {
		int result = id.hashCode();
		result = 31 * result + longtitude.hashCode();
		result = 31 * result + lattitude.hashCode();
		result = 31 * result + owner.hashCode();
		result = 31 * result + (int) (type ^ (type >>> 32));
		return result;
	}
}
